<div class="filter2">
    <div class="item f1" style="width: 120px;">
        <select data-am-selected="{maxHeight: 300}">
        </select>
    </div>
    <div class="item f2" style="width: 120px;">
        <input type="text" class="am-form-field" placeholder="" data-am-datepicker/>
    </div>
</div>

<table class="tr">
  <tr>
    <td style="width:4.5rem">期数</td>
    <td>开奖号码</td>
  </tr>
</table>

<div class="scroll-data"><div class="for-scroll">
    <table>
    </table>

    <div class="page_info">
        <div id="listPage" class="megas512 zxf_pagediv"></div>    
    </div>
</div></div>
<style type="text/css">
    .filter2 {
        height: 49px;
    }
    .filter2 .item {
        display: inline-block;
        line-height: 30px;
        margin: 9px 10px 0px 10px;
    }
    .filter2 .am-selected {
        width: 100%;
    }
    .filter2 .am-selected-btn, .filter2 input {
        background-color: rgba(0, 0, 0, 0.2);
        line-height: 30px;
        text-align: center;
        padding-top: 0px;
        padding-bottom: 0px;
        border-radius: 3px;
        border: 1px solid rgba(250,250,250,0.44);
        color: #fff;
        font-size: 0.6rem;
    }
    .filter2 .am-selected-list {
        font-size: 0.7rem;
        line-height: 1rem;
    }
    .tr {
        width: 100%;
        height: 35px;
        color: #fff;
        font-size: 0.7rem;
        line-height: 35px;
    }
    .tr td {
        text-align: center;
        box-shadow: inset -1px 1px 0 0 rgba(255,255,255,.21), 1px 1px 0 0 rgba(0,0,0,.13);
        background-color: rgba(255,255,255,0.2);
    }
    .scroll-data table {
        width: 100%;
        font-size: 0.6rem;
        color: #fff;
    }
    .scroll-data table td {
        text-align: center;
        box-shadow: inset -1px 1px 0 0 rgba(255,255,255,.21), 1px 1px 0 0 rgba(0,0,0,.25);
        padding: 10px 1px 10px 1px;
    }
    .scroll-data {
        position: absolute;
        left: 0px;
        right: 0px;
        top: 85px;
        bottom: 0px;
        overflow: hidden;
    }
    .result-wrap, .nums-wrap {
        text-align: center;
    }
</style>

<script>
    $("#center-top .home").hide();
    $("#center-top .back").show();
    $("#center-top .menu").hide();

    // 填充游戏
    var s = $(".f1 select");
    s.empty();
    var games = get_game_list();
    for (var i in games) {
        var g = games[i];
        s.append("<option value='" + g + "'>" + get_game_display_name(g) + "</option>");
    }
    s.val(game);
    s.trigger('changed.selected.amui');
    s.change(function() {
        queryKjjg();
    });

    // 填充日期
    $(".filter2 .f2 input").datepicker({ format: 'yyyy-mm-dd' });
    $(".filter2 .f2 input").datepicker("setValue", new Date().Format("yyyy-MM-dd"));
    $(".filter2 .f2 input").change(function() {
        queryKjjg();
    });

    // 拉取信息
    var queryKjjg = Util.queryTemplate($("#history_table tbody"), ".zxf_pagediv", $(".button button"), function(page, size, cb) {
        var g = $(".f1 select").val() || 'bjpk10';
        var data = {
            pageNum: page,
            pageSize: size || 20,
            type: g,
        };
        var start = new Date($(".f2 input").val()).getTime() - 8 * 3600 * 1000;
        var end = start + 3600 * 24 * 1000;

        if (g == 'lhc' && start) {
            start = null;
            end = null;
        }
        else if (new Date().getTime() - start < 2 * 3600 * 1000) {
            start = start - 2 * 3600 * 1000;
        }
        
        if (start) data.start = start;
        if (end) data.end = end;
        
        startLoading();
        CMD.lottery_query(data, function(r) {
            stopLoading();
            cb(r);
        });
    }, function(table, list, sum) {
        var table = $(".scroll-data table");
        table.empty();
        var g = $(".f1 select").val() || 'bjpk10';
        switch (g) {
            case "bjpk10":
            case "zypk10":
                _drawPk10(table, list); break;
            case "cqssc":
            case "xjssc":
            case "tjssc":
            case "zyssc":
            case "ffcqq":
                _drawSsc(table, list); break;
            case "cqkl10":
                _drawCqkl10(table, list); break;
            case "gdkl10":
            case "zykl10":
                _drawTen(table, list); break;
            case "gd115":
            case "zy115":
                _draw115(table, list); break;
            case "bjkl8":
            case "zykl8":
                _drawkl8(table, list); break;
            case "jsk3":
            case "zyk3":
                _drawk3(table, list); break;
            case "lhc":
                _drawlhc(table, list); break;
            }
            _mainScroll.refresh();
    });

    function _appendItem1(n) {
        return '<span class="round">' + n + '</span>';
    }
    function _appendItem2(n) {
        return '<span class="resultData">' + n + '</span>';
    }
    function _appendItem3(n) {
        var n = parseInt(n);
        var c = 'blue';
        if (LhcRule.hongbo().indexOf(n) != -1) c = 'red';
        else if (LhcRule.lanbo().indexOf(n) != -1) c = 'blue';
        else if (LhcRule.lvbo().indexOf(n) != -1) c = 'green';
        n = n < 10 ? '0' + n : n;
        return '<span class="round-4 ' + c + '">' + n + '</span>'
    }

    // pk10绘制
    function _drawPk10(table, list) {
        for (var i in list) {
            var o = list[i];
            if (!o.time.startsWith($(".f2 input").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td style='width:4.5rem'>" + o.issue + "<br>" + o.time.substring(5) + "</td>");

            var l = '<div class="nums-wrap">';
            var red = o.red
            for (var j in red) {
                l += '<span class="round-8 data-__i__"> </span>'.replace(/__i__/g, parseInt(red[j]));
            }
            l += '</div>';

            l += '<div class="result-wrap">';
            gy = parseInt(red[0]) + parseInt(red[1]);
            l += _appendItem2(gy);
            if (gy > 11) l += _appendItem2("大");
            else l += _appendItem2("小");
            if (gy % 2 == 0) l += _appendItem2("双");
            else l += _appendItem2("单");

            // 1~5龙虎
            for (var j = 0; j < 5; j++) {
                var v0 = parseInt(red[j]), v1 = parseInt(red[9 - j]);
                if (v0 > v1) l += _appendItem2("龙");
                else l += _appendItem2("虎");
            }
            l += "</div>";
            tr.append("<td>" + l + "</td>");
            table.append(tr);
        }
    }

    // 时时彩
    function _drawSsc(table, list) {
        var gameRule = Util.getGameRule("cqssc");
        for (var i in list) {
            var o = list[i];
            if (o.time && !o.time.startsWith($(".f2 input").val())) continue;
            var tr = $("<tr></tr>");
            if (o.time)
                tr.append("<td style='width:4.5rem'>" + o.issue + "<br>" + o.time.substring(5) + "</td>");
            else
                tr.append("<td style='width:4.5rem'>" + o.issue + "</td>");

            var l = '<div class="nums-wrap">';
            var red = o.red
            for (var j in red) {
                l += _appendItem1(red[j]);
            }
            l += '</div>';

            // 总和
            l += '<div class="result-wrap">';
            var he = gameRule.he(red);
            l += _appendItem2(he);
            if (gameRule.isHeBig(red)) l += _appendItem2("大");
            else l += _appendItem2("小");
            if (gameRule.isHeOdd(red)) l += _appendItem2("单");
            else l += _appendItem2("双");

            // 龙虎
            if (gameRule.isLong(red)) 
                _appendItem2("龙");
            else if (gameRule.isHu(red))
                _appendItem2("虎");
            else if (gameRule.isHe(red))
                _appendItem2("和");

            l += '</div>';
            tr.append("<td>" + l + "</td>");
            table.append(tr);
        }
    }

    // 重庆幸运农场
    function _drawCqkl10(table, list) {
        var gameRule = Util.getGameRule("cqkl10");
        for (var i in list) {
            var o = list[i];
            if (!o.time.startsWith($(".f2 input").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td style='width:4.5rem'>" + o.issue + "<br>" + o.time.substring(5) + "</td>");

            var l = '<div class="nums-wrap" style="text-align:center">';
            var red = o.red
            for (var j in red) {
                l += _appendItem1(red[j]);
            }
            l += '</div>';

            l += '<div class="result-wrap">';
            var he = gameRule.he(red);
            l += _appendItem2(he);
            if (gameRule.isHeBig(red)) l += _appendItem2("大");
            else if (gameRule.isHeSmall(red)) l += _appendItem2("小");
            else  l += _appendItem2("和");

            if (!gameRule.isOdd(he))  l += _appendItem2("双");
            else  l += _appendItem2("单");
            if (gameRule.isWeiDa(he))  l += _appendItem2("尾大");
            else  l += _appendItem2("尾小");

            // 1~4龙虎
            for (var i = 0; i < 4; i++) {
                if (gameRule.isLong(red, i))  l += _appendItem2("龙");
                else  l += _appendItem2("虎");
            }
            l += "</div>";
            tr.append("<td>" + l + "</td>");
            table.append(tr);
        }
    }

    // 快乐10
    function _drawTen(table, list) {
        var gameRule = Util.getGameRule("gdkl10");
        for (var i in list) {
            var o = list[i];
            if (!o.time.startsWith($(".f2 input").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td style='width:4.5rem'>" + o.issue + "<br>" + o.time.substring(5) + "</td>");

            var l = '<div class="nums-wrap" style="text-align:center">';
            var red = o.red
            for (var j in red) {
                l += _appendItem1(red[j]);
            }
            l += '</div>';

            l += '<div class="result-wrap">';
            var he = gameRule.he(red);
            l += _appendItem2(he);
            if (gameRule.isHeBig(red)) l += _appendItem2("大");
            else if (gameRule.isHeSmall(red)) l += _appendItem2("小");
            else  l += _appendItem2("和");

            if (!gameRule.isOdd(he))  l += _appendItem2("双");
            else  l += _appendItem2("单");
            if (gameRule.isWeiDa(he))  l += _appendItem2("尾大");
            else  l += _appendItem2("尾小");

            // 1~4龙虎
            for (var i = 0; i < 4; i++) {
                if (gameRule.isLong(red, i))  l += _appendItem2("龙");
                else  l += _appendItem2("虎");
            }

            tr.append("<td>" + l + "</td>");
            table.append(tr);
        }
    }

    // 11选5
    function _draw115(table, list) {
        var gameRule = Util.getGameRule("gd115");
        for (var i in list) {
            var o = list[i];
            if (!o.time.startsWith($(".f2 input").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td style='width:4.5rem'>" + o.issue + "<br>" + o.time.substring(5) + "</td>");

            var l = '<div class="nums-wrap" style="text-align:center">';
            var red = o.red
            for (var j in red) {
                l += _appendItem1(red[j]);
            }
            l += '</div>';

            l += '<div class="result-wrap">';            
            var he = gameRule.he(red);
            l += _appendItem2(he);
            if (gameRule.isHeBig(red))
                l += _appendItem2("大");
            else if (gameRule.isHeSmall(red))
                l += _appendItem2("小");
            else l += _appendItem2("和");
            if (gameRule.isHeOdd(red))
                l += _appendItem2("单");
            else
                l += _appendItem2("双");
            if (gameRule.isHeWeiBig(red))
                l += _appendItem2("尾大");
            else
                l += _appendItem2("尾小");

            // 龙虎
            if (gameRule.isLong(red))
                l += _appendItem2("龙");
            else if (gameRule.isHu(red))
                l += _appendItem2("虎");
            else if (gameRule.isHe(red))
                l += _appendItem2("和");
            l += "</div>";
            tr.append("<td>" + l + "</td>");
            table.append(tr);
        }
    }

    // 快乐8
    function _drawkl8(table, list) {
        var gameRule = Util.getGameRule("bjkl8");
        for (var i in list) {
            var o = list[i];
            if (!o.time.startsWith($(".f2 input").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td style='width:4.5rem'>" + o.issue + "<br>" + o.time.substring(5) + "</td>");

            var l = '<div class="nums-wrap" style="text-align:center">';
            var red = o.red
            for (var j in red) {
                if (j == 10) l += "<br>";
                l += _appendItem1(red[j]);
            }
            l += '</div>';
            tr.append("<td>" + l + "</td>");
            table.append(tr);
        }
    }

    // 快3
    function _drawk3(table, list) {
        var gameRule = Util.getGameRule("jsk3");
        for (var i in list) {
            var o = list[i];
            if (!o.time.startsWith($(".f2 input").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td style='width:4.5rem'>" + o.issue + "<br>" + o.time.substring(5) + "</td>");

            var l = '<div class="nums-wrap" style="text-align:center">';
            var red = o.red
            for (var j in red) {
                l += '<span class="round-10 data-__i__">__i__</span>'.replace(/__i__/g, parseInt(red[j]));
            }
            l += '</div>';

            l += '<div class="result-wrap">';
            var he = gameRule.he(red);
            l += _appendItem2(he);
            if (gameRule.isBaoZi(red)) l += _appendItem2("豹子");
            else if (gameRule.isHeBig(red)) l += _appendItem2("大");
            else l += _appendItem2("小");

            l += "</div>";
            tr.append("<td>" + l + "</td>");
            table.append(tr);
        }
    }

    // 六合彩
    function _drawlhc(table, list) {
        var gameRule = Util.getGameRule("lhc");
        for (var i in list) {
            var o = list[i];
            var tr = $("<tr></tr>");
            tr.append("<td style='width:4.5rem'>" + o.issue + "<br>" + o.time.substring(5) + "</td>");
            var l = '<div class="nums-wrap" style="text-align:left; padding:20px 0px 0px 10px;">';
            var red = o.red
            for (var j in red) {
                if (j == 6) l += '<span style="color:#fff;font-size:30px;float:left;">+</span>';
                l += _appendItem3(red[j]);
            }
            l += '<div class="clear"></div></div>';

            l += '<div class="result-wrap">';
            l += "</div>";
            tr.append("<td>" + l + "</td>");
            table.append(tr);
        }
    }

    var _mainScroll;
    $(function() {
        _mainScroll = new IScroll(".scroll-data", {
            scrollX: false,
            scrollY: true,
            click: true,
        })
    });
</script>